package com.wsoft.portal.controller;

import com.wsoft.portal.query.sub.ModuleSubInsertQuery;
import com.wsoft.portal.query.sub.ModuleSubUpdateQuery;
import com.wsoft.portal.service.IPortalModuleSubService;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 *  前端控制器
 * @author Z001
 * @since 2024年12月27日 10:01:48
 */
@RestController
@Tag(name = "栏目")
@RequestMapping("/portal/sub")
public class PortalModuleSubController {

    @Resource
    private IPortalModuleSubService subService;


    @Operation(summary = "新增栏目", description = "新增栏目")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ModuleSubInsertQuery query) {
        boolean b = subService.insertModuleSub(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改栏目", description = "修改栏目")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ModuleSubUpdateQuery query) {
        boolean b = subService.updateModuleSub(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "栏目详情", description = "栏目详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(subService.getModuleSubInfo(id));
    }

    @Operation(summary = "删除栏目", description = "删除栏目")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = subService.deleteModuleSub(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

}
